home *** CD-ROM | disk | FTP | other *** search
/ Aminet 45 / Aminet 45 (2001)(GTI - Schatztruhe)[!][Oct 2001].iso / Aminet / game / role / ldmud-3.2-bin.lha / mud / doc / efun / [] next >
Text File  |  2001-04-04  |  3KB  |  68 lines

  1. SYNOPSIS
  2.         mixed   arr[index]
  3.         int     str[index]
  4.  
  5.         mixed * arr[from .. to]
  6.         string  str[from .. to]
  7.  
  8. DESCRIPTION
  9.         Return one element from a string/array (first form), or a
  10.         slice (substring resp. subarray) of the string/array (second form).
  11.  
  12.         The indexes <index>, <from> and <to> are numbered 0 to
  13.         strlen(str)-1 resp. sizeof(arr)-1 .
  14.         If an index is written '<value', the value is counted from the
  15.         end of the string/array and is numbered 1 to strlen(str) resp.
  16.         sizeof(arr).
  17.         If <from> is omitted, it defaults to the beginning of the
  18.         string/array.
  19.         If <to> is omitted, it defaults to the beginning of the
  20.         string/array.
  21.         
  22.         In the first form, the <index> must be within the bounds of
  23.         the string/array, or a runtime error occurs.
  24.         In the second form, the indexes will be fitted to the bounds
  25.         of the string/array. If <from> is greater than <to>, or both
  26.         outside the bounds, an empty string/array ("" resp. ({})) will
  27.         be returned.
  28.  
  29.         The closure notation is straightforward:
  30.  
  31.           [index]      -> ({'#[,      arr, index })
  32.           [<index]     -> ({'#[<,     arr, index })
  33.           [from..to]   -> ({'#[..],   arr, from, to })
  34.           [<from..to]  -> ({'#[<..],  arr, from, to })
  35.           [from..<to]  -> ({'#[..<],  arr, from, to })
  36.           [<from..<to] -> ({'#[<..<], arr, from, to })
  37.  
  38. EXAMPLES
  39.         foo = ({ 1, 2, 3, 4 });                str = "test";
  40.  
  41.         foo[1]     -> 1                        str[1] -> 'e' == 101
  42.         foo[1..2]  -> ({ 2, 3 })        str[1..2]  -> "es"
  43.         foo[2..1]  -> ({ })                str[2..1]  -> ""
  44.         foo[0..<2] -> ({ 1, 2 })        str[0..<2]  -> "tes"
  45.         foo[..<2]  -> ({ 1, 2 })        str[..<2]  -> "tes"
  46.         foo[<3..]  -> ({ 2, 3, 4 })        str[<3..]  -> "est"
  47.  
  48.         foo[1] = 5                -> foo == ({ 1, 5, 3, 4 })
  49.         foo[1..2] = ({ 5, 6, 7 }) -> foo == ({ 1, 5, 6, 7, 4 })
  50.         foo[1..2] = ({ })         -> foo == ({ 1, 4 })
  51.  
  52.         str[1] = 'a'              -> str == "tast"
  53.         str[1..2] = "bar"         -> str == "tbart"
  54.         str[1..2] = ""            -> str == "tt"
  55.  
  56. HISTORY
  57.         slice_array() is the old form of the [] operator on arrays.
  58.         extract() is the old form of the [] operator on strings.
  59.         Both ARE NO LONGER SUPPORTED and should not be used anymore!
  60.  
  61.         The syntax for ``counting from last element'' has changed
  62.         between versions 3.1.J and 3.1.K from ``-1'' to ``<1''.
  63.         foo[0..-1] is now an empty string resp. array.
  64.  
  65. SEE ALSO
  66.         member(E), sizeof(E)
  67.  
  68.